*PITF GLOBAL MODEL REPLICATION
*
*Variables used in the PITF global model:
*
*SFTPTV2A='Regime type'
*LOGIM='Infant Mortality'
*MACCAT='Bordering States with Major Civil or Ethnic Conflict (4+ vs. 0-3)'
*DISP4CAT='State-Led Discrimination (yes vs. no)'
*
*Variables used in Fearon & Laitin model:
*
*LOG_GDPC='Per capita income, logged'
*LOGTPOP='Population, logged'
*LOGMTN ='% Mountainous, logged'
*FEANCTIG ='Noncontiguous state (Yes vs. No)'
*FLOIL ='Oil export revenues from fossil fuels of total export (>=1/3  vs. <1/3 )'
*SFTPDUR2 ='Instability dummy (three-step change in Polity IV scale, Yes vs. No)'
*ETHHERF ='Ethnic fractionalization'
*RELHREL ='Religious fractionalization'
*ANOCRACY ='Anocracy dummy (-5<=POLX<=5 vs. POLX<-5)'
*DEMOCRACY ='Democracy dummy (POLX>5 vs. POLX<-5)'
*
*Indicators to be used for subseting:
*
*MISS_IND ='subset to 0 to restrict global model to same sample size as F/L'
*GLB_IND = 'Y to run model for All Problems'
*CWAR_IND = 'Y to run model for Civil War Onsets'
*REG_IND = 'Y to run model for Adverse Regime Change Onsets'
*
*** Goldstoneetal_AJPS10
use "PITF Global Model Replication Data 121709.dta", clear


quietly tabulate sftptv2a, gen(sftptv2a)
label variable sftptv2a1 "Full autocracy"
label variable sftptv2a2 "Full democracy"
label variable sftptv2a3 "Partial autocracy"
label variable sftptv2a4 "Partial democracy with factionalism"
label variable sftptv2a5 "Partial democracy without factionalism"
label variable sftptv2a6 "Transition (-88)"
quietly tabulate byregn2, gen(byregn2_)
label variable byregn2_1 "AF"
label variable byregn2_2 "AS"
label variable byregn2_3 "EU"
label variable byregn2_4 "LA"
label variable byregn2_5 "ME"
label variable maccat "Armed conflict in 4+ bordering states"
label variable sftpcons "Instability onset indicator (DV)"
label variable logim "Infant mortality"
label variable disp4cat "State-led discrimination"
egen stratida = concat(year byregn2 group) if sample==1
egen stratidb = concat(year byregn2 group) if sample==2
egen stratidc = concat(year byregn2 group) if sample==3
label variable stratida "Stratum ID for Sample A"
label variable stratidb "Stratum ID for Sample B"
label variable stratidc "Stratum ID for Sample C"

ccode sftgname, from(cty) to(cow) gen(ccode)
tab sftgname if ccode==.
replace ccode = 484 if sftgname=="Congo-Brazzaville"
replace ccode = 490 if sftgname=="Congo-Kinshasa"
replace ccode = 530 if sftgname=="Ethiopia(1993-)"
replace ccode = 265 if sftgname=="Germany, East"
replace ccode = 731 if sftgname=="Korea, North"
replace ccode = 732 if sftgname=="Korea, South"
replace ccode = 770 if sftgname=="Pakistan(1947-1971)"
replace ccode = 770 if sftgname=="Pakistan(1972-)"
replace ccode = 52 if sftgname=="Trinidad"
replace ccode = 365 if sftgname=="USSR(Soviet Union)"
replace ccode = 817 if sftgname=="Vietnam, North"
replace ccode = 816 if sftgname=="Vietnam, South"
replace ccode = 679 if sftgname=="Yemen"
replace ccode = 680 if sftgname=="Yemen, North"
replace ccode = 679 if sftgname=="Yemen, South"
replace ccode = 345 if sftgname=="Yugoslavia, Former"

merge m:1 ccode using cites.dta, gen(m1)
drop if m1==2
gen cites = year>=citesyr

gen study = ""
foreach n in orig noth fe time fet ct yfe cyfe {
gen method_`n' = ""
gen dv_`n' = ""
gen b_cites_`n' = .
gen se_cites_`n'= .
gen pval_cites_`n' = .
gen lo_cites_`n'=.
gen hi_cites_`n'=.
gen N_cites_`n'=.
}
gen studynum=.
gen timetrend=""
qui do cites.do
local ii = 1
destring stratid* , replace
**Full Problem Set
* model 1
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & glb_ind=="Y", group(stratida)
cites `ii' orig
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & glb_ind=="Y", 
cites `ii' noth
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & glb_ind=="Y", group(stratida)
cites `ii' fe
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==1 & glb_ind=="Y", cl(stratida)
cites `ii' time
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==1 & glb_ind=="Y", group(stratida)
cites `ii' fet
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.ccode#c.year if sample==1 & glb_ind=="Y", cl(stratida)
cites `ii' ct
xtreg sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.year if sample==1 & glb_ind=="Y", i(stratida) cl(stratida)
cites `ii' cyfe
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & glb_ind=="Y", group(year)
cites `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1
* model 2
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & glb_ind=="Y", group(stratidb)
cites `ii' orig
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & glb_ind=="Y", 
cites `ii' noth
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & glb_ind=="Y", group(stratidb)
cites `ii' fe
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==2 & glb_ind=="Y", cl(stratidb)
cites `ii' time
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==2 & glb_ind=="Y", group(stratidb)
cites `ii' fet
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.ccode#c.year if sample==2 & glb_ind=="Y", cl(stratidb)
cites `ii' ct
xtreg sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.year if sample==2 & glb_ind=="Y",  i(stratidb) cl(stratidb)
cites `ii' cyfe
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & glb_ind=="Y", group(year)
cites `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1
* model 3
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & glb_ind=="Y", group(stratidc)
cites `ii' orig
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & glb_ind=="Y", 
cites `ii' noth
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & glb_ind=="Y", group(stratidc)
cites `ii' fe
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==3 & glb_ind=="Y", cl(stratidc)
cites `ii' time
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==3 & glb_ind=="Y", group(stratidc)
cites `ii' fet
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.ccode#c.year if sample==3 & glb_ind=="Y", cl(stratidc)
cites `ii' ct
xtreg sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.year if sample==3 & glb_ind=="Y",  i(stratidc) cl(stratidc)
cites `ii' cyfe
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & glb_ind=="Y", group(year)
cites `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1

**Civil War Onsets
* model 4
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & cwar_ind=="Y", group(stratida)
cites `ii' orig
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & cwar_ind=="Y", 
cites `ii' noth
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & cwar_ind=="Y", group(stratida)
cites `ii' fe
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==1 & cwar_ind=="Y", cl(stratida)
cites `ii' time
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==1 & cwar_ind=="Y", group(stratida)
cites `ii' fet
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.ccode#c.year if sample==1 & cwar_ind=="Y", cl(stratida)
cites `ii' ct
xtreg sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.year if sample==1 & cwar_ind=="Y",  i(stratida) cl(stratida)
cites `ii' cyfe
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & cwar_ind=="Y", group(year)
cites `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1
* model 5
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & cwar_ind=="Y", group(stratidb)
cites `ii' orig
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & cwar_ind=="Y", 
cites `ii' noth
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & cwar_ind=="Y", group(stratidb)
cites `ii' fe
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==2 & cwar_ind=="Y", cl(stratidb)
cites `ii' time
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==2 & cwar_ind=="Y", group(stratidb)
cites `ii' fet
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.ccode#c.year if sample==2 & cwar_ind=="Y", cl(stratidb)
cites `ii' ct
xtreg sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.year if sample==2 & cwar_ind=="Y",  i(stratidb) cl(stratidb)
cites `ii' cyfe
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & cwar_ind=="Y", group(year)
cites `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1
* model 6
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & cwar_ind=="Y", group(stratidc)
cites `ii' orig
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & cwar_ind=="Y", 
cites `ii' noth
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & cwar_ind=="Y", group(stratidc)
cites `ii' fe
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==3 & cwar_ind=="Y", cl(stratidc)
cites `ii' time
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==3 & cwar_ind=="Y", group(stratidc)
cites `ii' fet
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.ccode#c.year if sample==3 & cwar_ind=="Y", cl(stratidc)
cites `ii' ct
xtreg sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.year if sample==3 & cwar_ind=="Y",  i(stratidc) cl(stratidc)
cites `ii' cyfe
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & cwar_ind=="Y", group(year)
cites `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1

**Adverse Regime Change Onsets
* model 7
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & reg_ind=="Y", group(stratida)
cites `ii' orig
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & reg_ind=="Y", 
cites `ii' noth
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & reg_ind=="Y", group(stratida)
cites `ii' fe
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==1 & reg_ind=="Y", cl(stratida)
cites `ii' time
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==1 & reg_ind=="Y", group(stratida)
cites `ii' fet
xtreg sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.year if sample==1 & cwar_ind=="Y",  i(stratida) cl(stratida)
cites `ii' cyfe
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==1 & reg_ind=="Y", group(year)
cites `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1
* model 8
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & reg_ind=="Y", group(stratidb)
cites `ii' orig
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & reg_ind=="Y", 
cites `ii' noth
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & reg_ind=="Y", group(stratidb)
cites `ii' fe
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==2 & reg_ind=="Y", cl(stratidb)
cites `ii' time
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==2 & reg_ind=="Y", group(stratidb)
cites `ii' fet
xtreg sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.year if sample==2 & cwar_ind=="Y",  i(stratidb) cl(stratidb)
cites `ii' cyfe
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==2 & reg_ind=="Y", group(year)
cites `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1
* model 9
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & reg_ind=="Y", group(stratidc)
cites `ii' orig
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & reg_ind=="Y", 
cites `ii' noth
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & reg_ind=="Y", group(stratidc)
cites `ii' fe
logit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==3 & reg_ind=="Y", cl(stratidc)
cites `ii' time
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat year if sample==3 & reg_ind=="Y", group(stratidc)
cites `ii' fet
xtreg sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat i.year if sample==3 & cwar_ind=="Y",  i(stratidc) cl(stratidc)
cites `ii' cyfe
clogit sftpcons cites sftptv2a3 sftptv2a4 sftptv2a5 sftptv2a2 sftptv2a6 logim maccat disp4cat if sample==3 & reg_ind=="Y", group(year)
cites `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1

replace study = "Goldstone et. al." if studynum~=. 	

keep study-timetrend
drop if studynum==.
compress
save goldstone.dta , replace
